package com.xzz;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author 黄会准
 * @since 2020-11-18
 */
public class UniqueOccurrences {
    public static void main(String[] args) {
        System.out.println(uniqueOccurrences(new int[]{1,2,2,1,1,3}));
        System.out.println(uniqueOccurrences(new int[]{-3,0,1,-3,1,1,1,-3,10,0}));
        System.out.println(uniqueOccurrences(new int[]{1,2}));
    }
    public static boolean uniqueOccurrences(int[] arr) {
//        Map<Integer, Long> map = Arrays.stream(arr).boxed().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
//        Map<Long, Long> collect = map.values().stream().collect(Collectors.toMap(k -> k, Function.identity(), (k, v) -> k));
//        if(collect.size()==map.values().size()){
//            return true;
//        }else {
//            return false;
//        }
        HashMap<Integer,Integer> map = new HashMap();
        for (int n : arr) {
            map.put(n,map.getOrDefault(n,0)+1);
        }
        HashSet<Integer> countSet = new HashSet<>();
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if(countSet.contains(entry.getValue())){
                return false;
            }else {
                countSet.add(entry.getValue());
            }
        }
        return true;
    }
}
